<?php
	include_once 'isLogin.php';

	$table_name = "informations";
	//查询
    if($_POST['submit']='搜索'){
		$table="informations";
		$title=$_POST['title'];
		$id=$_POST['id'];
		$from=$_POST['froms'];
		
		if($_POST[title]=='' && $_POST[title]==null){
			$sql1="$table where froms like '%".$from."%'";
		}elseif($_POST[froms]=='' && $_POST[froms]==null){
			$sql1="$table where title like '%".$title."%'";
		}else{
			$sql1="$table where froms like '%".$from."%' or title like '%".$title."%'";
		}
		
		$select=$commonc->getList($sql1 , $sql1);
	   }
	   
	//添加
	if($_GET['action']=='add'){
		
		//插入数据
		if(is_array($_POST['values'])){
			foreach($_POST['values'] as $k=>$v){
				$arr[$key_index[$k]] = $v;
			}
		}
		$commonc->insert($table_name,$arr);
		$id = $commonc->insert_id();
		
		//排序
		$arr = array('sort'=>$id);
		$commonc->update($table_name, $arr, "id='".$id."'");
		
		//查询记录
		$data = $commonc->getInfo($table_name, $id);
		
	}
	
	//删除
	if($_GET['action']=='del'){
		$id=$_GET['id'];
		$a=$commonc->getInfo($table_name,$id,$key="*",$search_key="id",$debug='0');
		echo $commonc->del($table_name,$_POST['id'],$a);
		exit();
	}
	
	//修改
	if($_GET['action']=='edit'){
		$arr = array($key_index[$_POST['index']]=>$_POST['value']);
		echo $commonc->update($table_name,$arr,"id='".$_POST['value_id']."'");
		exit();
	}
	
	$smarty->assign("select",$select['result']);
	$smarty->assign("page",$select['page']);
	
	$smarty->display($_filename.".html");
?>